const express = require('express');
const router = express.Router();
const Database = require('../model/connectDatabase');
const {SuccessModel,ErrorModel} = require('../model/resData');

//接受username
router.get('/',function(req, res, next) {
  let database = new Database().mysql;
  let username = req.query.username
  let sql = 'select * from resources where(userId=?)'
  database.query('select id from users where(username=?)',[username],(err,data)=>{
    // console.log(data[0].id)
    // res.send(data[0])
    let userid = data[0].id
    database.query(sql,[userid],(error,response)=>{
      if(error){
        res.send(new ErrorModel(error,'数据库访问失败'))
      }else{
        res.send(new SuccessModel(response,'请求成功'))
      }
    })
  })
})
module.exports = router
